<template>
  <view
    class="detail_box"
    @touchmove="refresh.moveTouchendHandler"
    @touchstart="refresh.startTouchendHandler"
    @touchend="refresh.endTouchendHandler"
  >
    <!-- 预览图 -->
    <image class="cover" :src="detailData.activityCover" mode="aspectFill" />

    <!-- 活动信息 -->
    <view class="basic_info">
      <!-- 标题 -->
      <view class="title">
        <view class="typed">{{ detailData.category.categoryMsg }}</view>
        <view class="msg">{{ detailData.activityTitle }}</view>
      </view>

      <!-- 报名人数 -->
      <view class="enroll">{{ detailData.activityQuota }}人报名</view>

      <!-- 基本信息 -->
      <view class="info">
        <view class="item">
          <view class="left">活动时间</view>
          <view class="msg">{{ detailData.startTime }}</view>
        </view>
        <view class="item">
          <view class="left">活动名额</view>
          <view class="msg">{{ detailData.activityQuota }}</view>
        </view>
        <view class="item">
          <view class="left">活动地址</view>
          <view class="msg">{{ detailData.activityAddress }}</view>
        </view>
        <view class="item">
          <view class="left">参与要求</view>
          <view class="msg">{{ detailData.activityRequirement }} </view>
        </view>
      </view>

      <!-- 活动简介 -->
      <view class="synopsis">
        <view class="title"> 活动简介 </view>
        <view class="text" v-html="detailData.activitySynopsis"></view>
      </view>

      <!-- 分享按钮 -->
      <button class="share" open-type="share">
        <uni-icons type="weixin" color="rgb(94, 207, 30)" size="30" />
      </button>

      <!-- 按钮 -->
      <button-click
        :msg="'报名'"
        :is-disable="checkStateEnum(detailData.activityState,ActivitySateEnum.ENDED) "
      />

      <!-- 下拉刷新 -->
      <pull-down-refresh
        :opacity="refresh.moveBottom.value / 3"
        :enble-anim="refresh.isRefresh.value"
      />
    </view>
  </view>
</template>

<script lang="ts" setup>
import {
  ActivitySateEnum,
  checkStateEnum,
} from '@/config/enum/enum'
import { ReqSelectActivityDetail } from '@/api/activity'
import buttonClick from '@/components/common/button_click/button-click.vue'
import { refreshHandler } from '@/components/common/pull_down_refresh'
import type { Activity } from '@/config/data/data'
import { onLoad } from '@dcloudio/uni-app'
import { ref, watch } from 'vue'

//活动内容详情
const detailData = ref<Activity>({
  activityId: 0,
  activityTitle: '',
  activityCover: '',
  startTime: new Date(),
  endTime:  new Date(),
  activityQuota: 0,
  activityState: 0,
  activitySynopsis: '',
  activityRequirement: '',
  activityAddress: '',
  category: {
    categoryId: 0,
    categoryMsg: ''
  }
})

//页面加载
onLoad((e) => {
  if (e) {
    id.value = parseInt(e.id)
    getData()
  }
})

//下拉刷新
const refresh = refreshHandler(300)

//活动id
const id = ref(0)

//监听下拉刷新
watch(
  () => refresh.isRefresh.value,
  (newValue, oldValue) => {
    if (newValue) {
      getData()
    }
  }
)

//获取数据
const getData = () => {
  ReqSelectActivityDetail({ id: id.value })
    .then((res) => {
      if (res.code == 200 && res.data) {
        detailData.value = res.data
      }
    })
    .finally(() => {
      refresh.isRefresh.value ? refresh.refreshEnd(500) : ''
    })
}
</script>

<style scoped lang="scss">
.detail_box {
  width: calc(100% - 40rpx);
  padding: 20rpx;
  background-color: $uni-bg-color-grey;

  .cover {
    width: 100%;
    height: 300rpx;
    border-radius: 20rpx;
  }

  .basic_info {
    width: calc(100% - 60rpx);
    padding: 0 30rpx;
    background-color: $uni-bg-color;

    .title {
      display: flex;
      align-items: center;
      margin: 40rpx 0 30rpx;
      .typed {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 20rpx;
        background-color: rgba(250, 220, 99, 0.437);
        color: rgb(247, 129, 55);
        width: 80rpx;
        height: 36rpx;
        margin-right: 20rpx;
        border-radius: 18rpx;
      }

      .msg {
        width: calc(100% - 100rpx);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    .enroll {
      margin: 0 0 30rpx;
      font-size: 30rpx;
      color: rgb(79, 77, 77);
    }

    .info {
      width: calc(100% - 80rpx);
      padding: 40rpx;
      background-color: rgba(248, 234, 165, 0.064);
      border-radius: 15rpx;

      .item {
        display: flex;
        align-items: baseline;
        margin-bottom: 30rpx;

        &:last-child {
          margin-bottom: 0;
        }

        .left {
          width: 120rpx;
          margin-right: 30rpx;
          font-size: 30rpx;
          color: rgb(94, 91, 91);
        }

        .msg {
          font-size: 28rpx;
          width: calc(100% - 150rpx);
        }
      }
    }
  }

  .synopsis {
    width: calc(100% - 20rpx);
    padding: 10rpx;
    margin-top: 30rpx;
    background-color: $uni-bg-color;

    .title {
      font-size: 32rpx;
      height: 80rpx;
      line-height: 80rpx;
      color: rgb(83, 81, 81);
    }
    .text {
      width: 100%;
      letter-spacing: 2rpx;

      image {
        margin: 20rpx 0;
      }
    }
  }
}
.share {
  position: fixed;
  right: 60rpx;
  bottom: 200rpx;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  width: 90rpx;
  height: 90rpx;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: $uni-bg-color;
  box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px !important;

  &::after {
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
  }
}
</style>
